<!-- 班结记录 -->
<template>
  <div class="app-container">
    <!-- 上部分表单 -->
    <el-form
      class="globalSerchFormStyle"
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      label-width="68px"
      label-position="right"
    >
      <el-row style="margin-top: 15px">
        <el-col
          :span="6"
          v-if="['', null].includes($store.state.user.userLevel)"
        >
          <el-form-item label="油企名称" prop="enterpriseId" size="small">
            <el-select
              style="margin-left: 15px"
              v-model="queryParams.enterpriseId"
              :clearable="true"
              filterable
              placeholder="请选择油企名称"
              @change="handleSelectChange"
            >
              <el-option
                v-for="(item, index) in enterpriseList"
                :key="index"
                :value="item.enterpriseId"
                :label="item.enterpriseName"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>

        <el-col :span="6" v-if="!['2'].includes($store.state.user.userLevel)">
          <el-form-item
            label="油站名称"
            prop="stationId"
            clearable
            size="small"
          >
            <el-select
              style="margin-left: 15px"
              v-model="queryParams.stationId"
              :clearable="true"
              filterable
              placeholder="请选择油站名称"
            >
              <el-option
                v-for="item in stationList"
                :key="item.stationId"
                :label="item.stationName"
                :value="item.stationId"
              >
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>

        <el-col :span="6">
          <el-form-item label="班结ID" prop="classNo" clearable size="small">
            <el-input
              style="margin-left: 15px"
              v-model="queryParams.classNo"
              placeholder="请输入单据编号"
              clearable
              size="small"
            />
          </el-form-item>
        </el-col>

        <el-col :span="6">
          <el-form-item label="班结人" prop="createName" clearable size="small">
            <el-input
              style="margin-left: 15px"
              v-model="queryParams.createName"
              placeholder="请输入班结人"
              clearable
              size="small"
            />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row style="margin-top: 15px">
        <el-col :span="6">
          <el-form-item label="班结时间" prop="createdDate" size="small">
            <el-date-picker
              style="width: 20px; margin-left: 15px"
              value-format="yyyy-MM-dd HH:mm:ss"
              v-model="dateRangeCreatedDate"
              type="datetimerange"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              :default-time="['00:00:00', '23:59:59']"
              @change="changeDateRangeDate"
            >
            </el-date-picker>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <el-row class="global_el_rowStyle" :gutter="10">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-search"
          @click="handleQuery"
          size="mini"
          >查询</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-refresh"
          size="mini"
          @click="resetQuery"
          plain
          >重置</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          icon="el-icon-download"
          @click="handleExport"
          size="mini"
          plain
          >导出</el-button
        ></el-col
      >
    </el-row>

    <el-table
      style="width: 100%"
      :data="orderList"
      v-loading="loading"
      header-align="left"
      border
    >
      <el-table-column label="班结ID" prop="classNo" align="left" width="160">
      </el-table-column>

      <el-table-column
        label="油企"
        align="left"
        prop="enterpriseName"
        v-if="[null].includes($store.state.user.userLevel)"
      >
      </el-table-column>
      <el-table-column
        label="油站名称"
        prop="stationName"
        align="left"
        width="160"
        v-if="!['2'].includes($store.state.user.userLevel)"
      >
      </el-table-column>
      <el-table-column
        label="班结开始时间"
        prop="classStartTime"
        align="left"
        width="160"
      >
      </el-table-column>
      <el-table-column
        label="班结结束时间"
        prop="classEndTime"
        align="left"
        width="160"
      >
      </el-table-column>
      <el-table-column
        label="销售合计应收（元）"
        prop="payableAmount"
        align="left"
        width="160"
      >
      </el-table-column>
      <el-table-column
        label="销售合计实收（元）"
        prop="actuallyAmount"
        align="left"
        width="160"
      >
      </el-table-column>
      <el-table-column
        label="销售合计优惠（元）"
        prop="totalDiscountAmount"
        align="left"
        width="160"
      >
      </el-table-column>
      <el-table-column
        label="退款金额（元）"
        prop="refundAmount"
        align="left"
        width="160"
      >
      </el-table-column>
      <el-table-column
        label="班结人"
        prop="createName"
        align="left"
        width="160"
      >
      </el-table-column>
      <el-table-column fixed="right" label="操作" width="100">
        <template slot-scope="scope">
          <el-button @click="handleClick(scope.row)" type="text" size="small"
            >详情</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <!-- 分页 -->
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>
<script>
import { nonOilList } from "@/api/nonOil/class";
import {
  enterpriseList,
  listEnterpriseStation,
} from "@/api/nonOil/putlntoStorage";
// import {
//   exportBusinessDailyReportList,
// } from "@/api/overview";
export default {
  name: "ShiftRecord",
  data() {
    return {
      table: false,
      enterpriseList: [],
      stationList: [],
      //时间间隔值
      dateRangeCreatedDate: [],
      // 总条数
      total: 0,
      // 统计数据
      workSum: {},
      //表格数据
      orderList: [],
      // 弹出层标题
      title: "",
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        enterpriseId: null,
        stationId: null,
        // 开始时间
        beginTime: null,
        // 截止时间
        endTime: null,
        createName: null,
        classNo: null,
      },
      isOnlyOneStation: false, // 当前油企是否只有一个正常使用的油站
      loading: false,
    };
  },
  created() {
    // 油企
    if (this.presentEnterprise && this.presentEnterprise.enterpriseId) {
      this.queryParams.enterpriseId = this.presentEnterprise.enterpriseId;
      this.getStationList(this.queryParams.enterpriseId);
    }
    // 油站账号登录
    if (this.presentSation) {
      this.queryParams.stationId = this.presentSation;
      this.handleQuery();
    }
    this.getList();
    this.getEnterpriseList();
  },

  methods: {
    handleClick(row) {
      this.$router.push({
        path: "/nonOil/shiftRecord_see",
        query: {
          classNo: row.classNo,
        },
      });
    },

    // 选择了时间
    changeDateRangeDate() {
      // 开始时间
      this.queryParams.beginTime = this.dateRangeCreatedDate
        ? this.dateRangeCreatedDate[0]
        : null;
      // 截止时间
      this.queryParams.endTime = this.dateRangeCreatedDate
        ? this.dateRangeCreatedDate[1]
        : null;
    },

    // 请选择油企
    handleSelectChange(value) {
      this.stationList = [];
      this.queryParams.stationId = null;
      this.getStationList(value);
    },

    // 查询油企
    getEnterpriseList() {
      enterpriseList().then((res) => {
        this.enterpriseList = res.rows;
      });
    },

    // 查询油站
    getStationList(val) {
      listEnterpriseStation({ enterpriseId: val, status: "1" }).then((res) => {
        this.stationList = res;
      });
    },

    // 搜索列表
    getList() {
      this.loading = true;
      let queryParams = this.queryParams;
      nonOilList(queryParams)
        .then((response) => {
          this.loading = false;
          this.orderList = response.rows;
          this.total = response.total;
        })
        .catch(() => {
          this.loading = false;
          this.orderList = [];
          this.total = 0;
        });
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },

    /** 重置按钮操作 */
    resetQuery() {
      this.dateRangeCreatedDate = [];
      // 开始时间
      this.queryParams.beginTime = null;
      // 截止时间
      this.queryParams.endTime = null;
      this.resetForm("queryForm");
      this.getList();
    },

    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;

      this.$confirm("是否确认导出所有数据项?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(function () {
          // return exportBusinessDailyReportList(queryParams);
        })
        .then((response) => {
          // this.download(response.msg);
        });
    },
  },
};
</script>
<style lang="scss" scoped>
.tree-item {
  border: 1px solid #e7e7e7;
  width: 200px;
}

.div-tree {
  display: flex;
}

.app-container {
  margin-top: -15px;
}

::v-deep .card-table {
  padding: 10px;
  margin-top: 0 !important;
  background-color: #f8f8f8;

  .el-button {
    margin: 0 5px 0 0;
  }
}

// 表格样式
::v-deep .el-form-item {
  margin-bottom: 0;

  .el-form-item__label {
    padding: 0;
    margin: 0;
    height: 29px;
    font-weight: 400;
    font-size: 12px;
  }
}

::v-deep .el-table {
  border: 1px #f8f8f8 solid;
  border-bottom: 1px #dfe6ec solid;
}

::v-deep .is-center {
  border: 1px transparent solid;
  border-bottom: 1px #f8f8f8 solid;
}
</style>
